﻿using CloudMusic.API;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows;
using CloudMusic.Helper;
using CloudMusic.ViewModel;
using System;
using System.Windows.Controls;
using System.Windows.Input;
using CloudMusic.Controls;
using CloudMusic.View;
using CloudMusic.UC;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System.IO;
using System.Windows.Media.Imaging;
using System.Collections.Generic;
using MyCustomControlLibrary;
using CloudMusic.Model;

namespace CloudMusic
{
    public partial class MainWindow
    {
        private bool openpanel = false;
        private bool IsSlider = false;
        private bool isMute = false;
        private System.Windows.Forms.NotifyIcon notifyIcon = null;
        DataServiceHelper ds = new DataServiceHelper();
        private Double volum = 0;
        public MainWindow()
        {
            InitializeComponent();
            GetUserInfo();
            //系统托盘
            SystemTrayParameter pars = new SystemTrayParameter("../../Image/Logo/icon.ico", this.Title, "", 0, notifyIcon_MouseClick);
            this.notifyIcon = SystemTrayHelper.SetSystemTray(pars, GetList());

            big.ToolTip = "最大化";
            this.SizeChanged += new SizeChangedEventHandler(MainWindow_Resize);
            //this.Deactivated += new EventHandler(Form1_Deactivate);
            findMusic.IsChecked = true;

 

            //Command = "{x:Static NavigationCommands.BrowseForward}"

            pageNext.Command = NavigationCommands.BrowseForward;
            pagePrv.Command = NavigationCommands.BrowseBack;


        }
        private void mainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            #region 音乐详情页面操作

            UCMusicDetail.closeDetail.Click += new RoutedEventHandler(coverBtn_Click);
            UCMusicDetail.album.MouseLeftButtonDown += new MouseButtonEventHandler(GoTo_Album);
            UCMusicDetail.artist.MouseLeftButtonDown += new MouseButtonEventHandler(GoTo_Artist);
            UCMusicDetail.musicSource.MouseLeftButtonDown += new MouseButtonEventHandler(GoTo_Source);
            UCMusicDetail.storeBtn.Click += StoreBtn_Click;

            //UCStoreWin.UCStoreClose += UCStoreWin_UCStoreClose;
 
            #endregion

            #region 用户简要消息页

            ucuserinfo.loginOut += Ucuserinfo_loginOut; ;
            ucuserinfo.LostFocusHide += Ucuserinfo_LostFocusHide;

            #endregion

            playListPanel.closePlayList.Click += new RoutedEventHandler(closePlayList_Click);
            playListPanel.LostFocusHide += PlayListPanel_LostFocusHide;
            UCsd.fx.Click += Fx_Click;

            ucstore.closeStorePanel.Click += CloseStorePanel_Click;
            ucstore.storeToList.SelectionChanged += StoreToList_SelectionChanged;

        }

        private void StoreToList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            int i = ucstore.storeToList.SelectedIndex;
            ucstore.storeToList.SelectedIndex = i;
            if (ucstore.storeToList.SelectedIndex != -1)
            {
                StoreListModel music = (StoreListModel)ucstore.storeToList.SelectedValue;
                var vm = DataContext as MainWindowViewModel;
                long id = vm.selectedMusic.Id;
                //var strResut = CommonHelper.Get("http://localhost:3000/playlist/tracks?op=add&pid="+ music.id + "&tracks="+ id + "&Cookie="+PlayListHelper.UserInfos[0].Cookie);
                //MMessageBox.ShowAlert(strResut,  Orientation.Horizontal,  null, "#3ca9fe", false);
                //MessageBox.Show(id.ToString() + " : " + music.id.ToString());
            }
            if (ucstore.storeToList.SelectedIndex == -1) return;
            ucstore.storeToList.SelectedIndex = -1;
        }

        /// <summary>
        /// 关闭打开的收藏到歌单窗口
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CloseStorePanel_Click(object sender, RoutedEventArgs e)
        {
            storePanel.Visibility = Visibility.Collapsed;
        }
        /// <summary>
        /// 读取
        /// </summary>
        public void GetUserInfo()
        {
            try
            {
                if (PlayListHelper.UserInfos != null)
                {
                    if (PlayListHelper.UserInfos[0].LonginState == 1 && PlayListHelper.UserInfos[0].IsChecked == true)
                    {
                        GetUserLikeList();
                        ViewUserInfoData();
                        GetLikesId();
                    }
                }
            }
            catch { }
        }

        #region 系统托盘

        //托盘右键菜单集合
        private List<SystemTrayMenu> GetList()
        {
            List<SystemTrayMenu> ls = new List<SystemTrayMenu>();
            ls.Add(new SystemTrayMenu() { Txt = "打开主面板", Icon = "", Click = mainWin_Click });
            ls.Add(new SystemTrayMenu() { Txt = "退出", Icon = "", Click = exit_Click });
            return ls;
        }
        //双击事件
        private void notifyIcon_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                this.Show();
                this.Activate();
            }

        }
        #region 托盘右键菜单
        //打开主面板
        private void mainWin_Click(object sender, EventArgs e)
        {
            this.Show();
            this.Activate();
        }
        //退出
        private void exit_Click(object sender, EventArgs e)
        {
            this.Close();
            Environment.Exit(0);
        }
        #endregion
        #endregion


        private void Fx_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("1");
        }

        /// <summary>
        /// 退出登录用户登录状态
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Ucuserinfo_loginOut(object sender, RoutedEventArgs e)
        {
            ucuserinfo.Visibility = Visibility.Collapsed;
            AvatarUrl.ImageSource = new BitmapImage(new Uri(@"pack://application:,,,/Image/demo.jpg"));
            AvatarName.Text = "未登录";
            vipImg.Visibility = Visibility.Collapsed;
            openVIP.Visibility = Visibility.Visible;
            storeExpander.Visibility = Visibility.Collapsed;
            AddSongList.Children.RemoveRange(0, AddSongList.Children.Count);
            ImageRadioButton bt = new ImageRadioButton { Style = FindResource("imageRadioButton") as Style };
            bt.ImageWidth = 16;
            bt.Image = FindResource("Icon_CanceLike") as Geometry;
            bt.Content = "我喜欢的音乐";
            bt.GroupName = "Menu";
            bt.Tag = "{id:\"0\",highQuality:\"False\"}";
            bt.Click += Bt_Checked;
            AddSongList.Children.Add(bt);
        }

        /// <summary>
        /// 用户信息简要面板失去焦点隐藏
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Ucuserinfo_LostFocusHide(object sender, RoutedEventArgs e)
        {
            ucuserinfo.Visibility = Visibility.Collapsed;
        }
        /// <summary>
        /// 播放列表面板失去焦点隐藏
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PlayListPanel_LostFocusHide(object sender, RoutedEventArgs e)
        {
            // playListPanel.BeginStoryboard(FindResource("ClosePlayListPanel") as Storyboard);
            playListPanel.Visibility = Visibility.Collapsed;
        }
        /// <summary>
        /// 获取用户喜欢和收藏的歌单-这里主要是获取名字以及id
        /// </summary>
        private void GetUserLikeList()
        {
            var json = CommonHelper.Get("http://localhost:3000/user/playlist?uid=" + PlayListHelper.UserInfos[0].UserId);
            if (json.Length > 0)
            {
                storeExpander.Visibility = Visibility.Visible;
                JObject obj = (JObject)JsonConvert.DeserializeObject(json);
                var list = JsonConvert.SerializeObject(obj["playlist"].ToString());
                JsonReader reader = new JsonTextReader(new StringReader(list));
                while (reader.Read())
                {
                    list = reader.Value.ToString();
                }
                JArray ja = (JArray)JsonConvert.DeserializeObject(list);
                //获取数值
                foreach (JObject jo in ja)
                {
                    if ((int)jo["specialType"] == 5)
                    {
                        myLike.Tag = "{id:\"" + jo["id"] + "\",highQuality:\"" + jo["highQuality"] + "\"}";
                        myLike.Checked += Bt_Checked;
                        PlayListHelper.StoreList.Add(new Model.StoreListModel
                        {
                            name = "我喜欢的音乐",
                            id = Convert.ToInt64(jo["id"].ToString()),
                            userId = Convert.ToInt64(jo["userId"].ToString()),
                            num = jo["trackCount"].ToString(),
                            coverImgUrl = jo["coverImgUrl"].ToString()
                        });
                    }
                    else
                    {
                        ImageRadioButton bt = new ImageRadioButton { Style = FindResource("imageRadioButton") as Style };
                        bt.ImageWidth = 16;
                        bt.Image = FindResource("Icon_MusicList") as Geometry;
                        bt.Content = jo["name"].ToString().Length > 11 ? jo["name"].ToString().Substring(0, 9) + "..." : jo["name"].ToString();
                        bt.ToolTip = jo["name"].ToString();
                        bt.Tag = "{id:\"" + jo["id"] + "\",highQuality:\"" + jo["highQuality"] + "\"}";
                        bt.GroupName = "Menu";
                        bt.Checked += Bt_Checked;
                        if ((long)jo["userId"] == PlayListHelper.UserInfos[0].UserId)
                        {
                            PlayListHelper.StoreList.Add(new Model.StoreListModel
                            {
                                name = jo["name"].ToString(),
                                id = Convert.ToInt64(jo["id"].ToString()),
                                userId = Convert.ToInt64(jo["userId"].ToString()),
                                num = jo["trackCount"].ToString(),
                                coverImgUrl = jo["coverImgUrl"].ToString()
                            });
                            AddSongList.Children.Add(bt);
                        }
                        else { storeList.Children.Add(bt); };
                    }

                }

            }
        }
        /// <summary>
        /// 鼠标进入-主窗体/当前播放歌曲封面出现
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CoverBtn_MouseEnter(object sender, MouseEventArgs e)
        {
            AlbumCover.Visibility = Visibility;
        }
        /// <summary>
        /// 鼠标离开-主窗体/当前播放歌曲封面隐藏
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CoverBtn_MouseLeave(object sender, MouseEventArgs e)
        {
            AlbumCover.Visibility = Visibility.Hidden;
        }
        /// <summary>
        /// 窗体大小发生改变
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainWindow_Resize(object sender, EventArgs e)
        {
            if (mainWindow.WindowState == WindowState.Maximized)
            {
                big.ToolTip = "向下还原";
                playListPanel.Height = 835;
            }
            else
            {
                playListPanel.Height = 465;
                big.ToolTip = "最大化";
            }
        }
        /// <summary>
        /// 导航返回上一页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pagePrv_Click(object sender, RoutedEventArgs e)
        {
            if (openpanel)
            {
                pagePrv.Command = NavigationCommands.BrowseStop;
                UCMusicDetail.BeginStoryboard(FindResource("ClosePanel") as Storyboard);
                openpanel = !openpanel;
            }
            else
            {
                pagePrv.Command = NavigationCommands.BrowseBack;
            }

        }
        /// <summary>
        /// 导航到下页面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pageNext_Click(object sender, RoutedEventArgs e)
        {
            if (openpanel)
            {
                pageNext.Command = NavigationCommands.BrowseStop;
                UCMusicDetail.BeginStoryboard(FindResource("ClosePanel") as Storyboard);
                openpanel = !openpanel;
            }
            else
            {
                pageNext.Command = NavigationCommands.BrowseForward;
            }
        }
        /// <summary>
        /// 分享按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ShareBtn_Click(object sender, RoutedEventArgs e)
        {
            SharePop.IsOpen = false;
            SharePop.IsOpen = true;

        }
        /// <summary>
        /// popup 阻止下一次鼠标点击
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddSheetPop_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            e.Handled = true;
        }

        #region 歌曲详情鼠标事件
        /// <summary>
        /// 关闭歌曲详情页面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void coverBtn_Click(object sender, RoutedEventArgs e)
        {
            if (openpanel)
            {
                UCMusicDetail.BeginStoryboard(FindResource("ClosePanel") as Storyboard);
            }
            else
            {
                UCMusicDetail.BeginStoryboard(FindResource("OpenPanel") as Storyboard);
            };
            openpanel = !openpanel;
        }

        /// <summary>
        /// 鼠标点击窗口左下角歌曲详情触发打开歌曲详情页面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CoverImgBtn_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (openpanel)
            {
                UCMusicDetail.BeginStoryboard(FindResource("ClosePanel") as Storyboard);
            }
            else
            {
                UCMusicDetail.BeginStoryboard(FindResource("OpenPanel") as Storyboard);
            };
            openpanel = !openpanel;
        }
        /// <summary>
        /// 跳转到专辑页面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GoTo_Album(object sender, MouseButtonEventArgs e)
        {
            coverBtn_Click(sender, e);
            var data = DataContext as MusicViewModelBase;
            var ps = new PageAlbumInfoViewModel(data.SelectedMusic.AlbumId);
            PageAlbumInfo pageAlbumInfo = new PageAlbumInfo(ps);
            this.Frame.Navigate(pageAlbumInfo);
        }
        /// <summary>
        /// 跳转到艺术家页面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GoTo_Artist(object sender, MouseButtonEventArgs e)
        {
            coverBtn_Click(sender, e);
            //var data = DataContext as MusicViewModelBase;
            //var ps = new PageSongSheetDetailViewModel(data.SelectedMusic.SingerId);
            //PageSongSheetDetail pageSongSheetDetail = new PageSongSheetDetail(ps, data.SelectedMusic.SingerId);
            //this.Frame.Navigate(pageSongSheetDetail);
        }
        /// <summary>
        /// 跳转到来源页面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GoTo_Source(object sender, MouseButtonEventArgs e)
        {
            coverBtn_Click(sender, e);
            var data = DataContext as MusicViewModelBase;
            var ps = new PageSongSheetDetailViewModel(data.SelectedMusic.SongId, data.SelectedMusic.HighQuality);
            switch (data.SelectedMusic.HighQuality)
            {
                case 1:
                case 2:
                    PageSongSheetDetail pageSongSheetDetail = new PageSongSheetDetail(ps, data.SelectedMusic.SingerId, data.SelectedMusic.HighQuality);
                    this.Frame.Navigate(pageSongSheetDetail);
                    break;
                case 3:
                    this.Frame.Navigate(new PageLocalMusic());
                    break;
                case 4:
                    this.Frame.Navigate(new PageDaySongs());
                    break;
                default:
                    break;
            }
        }
        /// <summary>
        /// 打开收藏到歌单列表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void StoreBtn_Click(object sender, RoutedEventArgs e)
        {
            storePanel.Visibility = Visibility.Visible;
            ucstore.storeToList.ItemsSource = PlayListHelper.StoreList;
            //if (PlayListHelper.StoreList.Count > 0)
            //{
            //    for (int i = 0; i < PlayListHelper.StoreList.Count; i++)
            //    {
            //        Button bt = default;
            //        bt = new Button { Style = FindResource("storeStyleBtn") as Style, DataContext = PlayListHelper.StoreList[i] };
            //        bt.Click += storeBt_Click;
            //        //ucstore.storeBtn.Children.Add(bt);
            //    }
            //}
            
        }

        private void storeBt_Click(object sender, RoutedEventArgs e)
        {
            var vm = DataContext as MainWindowViewModel;
            long id = vm.selectedMusic.Id;
            MessageBox.Show(id.ToString());
        }
        #endregion

        #region 播放条操作事件/音量操作事件
        /// <summary>
        /// 播放进度条滑动事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PlaySlider_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
        {
            IsSlider = false;
        }
        /// <summary>
        /// 开始滑动
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PlaySlider_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
        {
            IsSlider = true;
        }
        /// <summary>
        /// 鼠标左键抬起触发滑块位置改变
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PlaySlider_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            PlayManager.PositionChange(PlaySlider.Value);
            IsSlider = false;
        }
        /// <summary>
        /// 鼠标上移
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PlaySlider_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed) IsSlider = true;
        }

        /// <summary>
        /// 进度条滑动值改变触发事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MunSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            PlayManager.VolumeChange(MunSlider.Value);
        }
        /// <summary>
        /// 音量静音与否按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MuteBtn_Click(object sender, RoutedEventArgs e)
        {
            if (!isMute)
            {
                PlayManager.ChangeVolumeState(true);
                volum = MunSlider.Value;
                MunSlider.Value = 0;
            }
            else
            {
                PlayManager.ChangeVolumeState(false);
                MunSlider.Value = volum;
            }
            isMute = !isMute;
        }
        #endregion

        #region 添加类操作事件
        /// <summary>
        /// 打开创建歌单按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void openCreate_Click(object sender, RoutedEventArgs e)
        {
            AddSheetPop.IsOpen = true;
        }

        private void playListBotton_MouseDown(object sender, MouseButtonEventArgs e)
        {
            //Point p = e.GetPosition(playListBotton);
            //string vv = "x:" + p.X + " y:" + p.Y;
        }
        #endregion 

        #region 播放歌面板交互
        /// <summary>
        /// 关闭播放歌单面板
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void closePlayList_Click(object sender, RoutedEventArgs e)
        {
            playListPanel.Visibility = Visibility.Collapsed;
            /// playListPanel.BeginStoryboard(FindResource("ClosePlayListPanel") as Storyboard);
        }
        /// <summary>
        /// 歌单按钮点击后歌单面板隐藏与否事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void openPlayListPanelBtn_Click(object sender, RoutedEventArgs e)
        {
            playListPanel.Visibility = playListPanel.Visibility == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible;
            //if (playListPanel.Visibility == Visibility.Collapsed)
            //{
            //    playListPanel.playPanel.Focus();
            //    playListPanel.BeginStoryboard(FindResource("OpenPlayListPanel") as Storyboard);
            //}
            //else
            //{
            //    playListPanel.BeginStoryboard(FindResource("ClosePlayListPanel") as Storyboard);
            //};
        }
        /// <summary>
        /// listview 滚动联动
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void NowPlayListView_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
        {
            CommonHelper.RunScorllView(sender, e);
        }
        #endregion 

        #region 添加歌单面板交互
        /// <summary>
        /// 鼠标进入
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void NewSongListAdd_MouseEnter(object sender, MouseEventArgs e)
        {
            if (this.addInfo.Text != "")
            {
                newSongListAdd.Background = new SolidColorBrush(Color.FromRgb(17, 103, 168));
            }
        }
        /// <summary>
        /// 鼠标离开
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void NewSongListAdd_MouseLeave(object sender, MouseEventArgs e)
        {

            if (this.addInfo.Text != "")
            {
                newSongListAdd.Background = new SolidColorBrush(Color.FromRgb(12, 115, 194));
            }
        }
        /// <summary>
        /// 鼠标点击
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void newSongListCancel_Click(object sender, RoutedEventArgs e)
        {
            this.checkbox.IsChecked = false;
            this.addInfo.Text = string.Empty;
            AddSheetPop.Focusable = false;
            AddSheetPop.IsOpen = false;
        }
        /// <summary>
        /// 文本框发生改变
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddInfo_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (this.addInfo.Text != "")
            {
                newSongListAdd.Cursor = Cursors.Hand;
                newSongListAdd.Background = new SolidColorBrush(Color.FromRgb(12, 115, 194));
            }
            else
            {
                newSongListAdd.Cursor = Cursors.Arrow;
                newSongListAdd.Background = new SolidColorBrush(Color.FromRgb(150, 192, 225));
            }
        }
        /// <summary>
        /// 添加按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void newSongListAdd_Click(object sender, RoutedEventArgs e)
        {
            if (this.addInfo.Text != "")
            {
                var ss = AddSongList.Children[0];
                ImageRadioButton bt = new ImageRadioButton { Style = FindResource("imageRadioButton") as Style };
                bt.ImageWidth = 16;
                bt.Image = FindResource("Icon_MusicList") as Geometry;
                bt.Content = addInfo.Text;
                bt.Tag = "1";
                bt.GroupName = "Menu";
                bt.Checked += Bt_Checked;
                AddSongList.Children.Add(bt);
                newSongListCancel_Click(sender, e);
            }

        }
        /// <summary>
        /// 跳转到歌单页面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Bt_Checked(object sender, RoutedEventArgs e)
        {
            ImageRadioButton irb = sender as ImageRadioButton;
            JObject job = (JObject)JsonConvert.DeserializeObject(irb.Tag.ToString());
            var id = job["id"].ToString().Replace('{', ' ').Replace('}', ' ').Trim();
            int highQuality = job["highQuality"].ToString() == "False" ? 1 : 2;
            var ps = new PageSongSheetDetailViewModel(Convert.ToInt64(id), highQuality);
            PageSongSheetDetail pageSongSheetDetail = new PageSongSheetDetail(ps, Convert.ToInt64(id), highQuality);
            this.Frame.Navigate(pageSongSheetDetail);
        }
        #endregion

        #region 分享按钮交互
        #endregion

        #region 登录操作后续

        /// <summary>
        /// 打开登录面板
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void userLogin_Click(object sender, RoutedEventArgs e)
        {

            if (PlayListHelper.UserInfos.Count > 0)
            {

                if (PlayListHelper.UserInfos[0].LonginState == 1)
                {
                    ucuserinfo.userInfo.Focus();
                    ucuserinfo.signinBtn.IsEnabled = false;
                    ucuserinfo.signinIcon.Visibility = Visibility.Collapsed;
                    ucuserinfo.signinName.Text = "已签到";
                    ucuserinfo.Visibility = ucuserinfo.Visibility == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible;
                }
                else
                {
                    UCLogin uC = new UCLogin();
                    uC.Owner = mainWindow;
                    uC.loginEvent += UC_loginEvent;
                    uC.Show();
                }
            }
            else
            {
                UCLogin uC = new UCLogin();
                uC.Owner = mainWindow;
                uC.loginEvent += UC_loginEvent;
                uC.Show();
            }
        }
        /// <summary>
        /// 登录信息显示主窗体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UC_loginEvent(object sender, EventArgs e)
        {
            GetUserLikeList();
            ViewUserInfoData();
            GetLikesId();

        }
        /// <summary>
        /// 用户信息
        /// </summary>
        private void ViewUserInfoData()
        {
            AvatarUrl.ImageSource = new BitmapImage(new Uri(PlayListHelper.UserInfos[0].AvatarUrl));
            AvatarName.Text = PlayListHelper.UserInfos[0].Nickname;
            ucuserinfo.userImg.ImageSource = new BitmapImage(new Uri(PlayListHelper.UserInfos[0].AvatarUrl));
            ucuserinfo.userName.Text = PlayListHelper.UserInfos[0].Nickname;
            ucuserinfo.dt.Content = PlayListHelper.UserInfos[0].EventCount.ToString();
            ucuserinfo.fs.Content = PlayListHelper.UserInfos[0].Followeds.ToString();
            ucuserinfo.gz.Content = PlayListHelper.UserInfos[0].Follows.ToString();
            if (PlayListHelper.UserInfos[0].VipType == 11)
            {
                ucuserinfo.vipType.Visibility = Visibility.Visible;
                ucuserinfo.userName.Width = 75;
                vipImg.Visibility = Visibility.Visible;
                openVIP.Visibility = Visibility.Collapsed;
            }
            //switch (PlayListHelper.UserInfos[0].VipType)
            //{
            //    case 11:
            //        ucuserinfo.vipType.Visibility = Visibility.Visible;
            //        ucuserinfo.userName.Width = 75;
            //        vipImg.Visibility = Visibility.Visible;
            //        openVIP.Visibility = Visibility.Collapsed;
            //        break;
            //    case 0:
            //        ucuserinfo.vipType.Visibility = Visibility.Collapsed;
            //        ucuserinfo.userName.Width = 105;
            //        vipImg.Visibility = Visibility.Collapsed;
            //        break;
            //    default:
            //        ucuserinfo.vipType.Visibility = Visibility.Collapsed;
            //        ucuserinfo.userName.Width = 105;
            //        vipImg.Visibility = Visibility.Collapsed;
            //        break;
            //}
        }
        private void GetLikesId()
        {
            var likes = CommonHelper.GetEquipList<LikesIdModel>(1, "http://localhost:3000/likelist?uid=" + PlayListHelper.UserInfos[0].UserId + "&cookie=" + PlayListHelper.UserInfos[0].Cookie);
            if (likes.code != 200) return;
            if (likes.ids.Count != 0)
            {
                PlayListHelper.UserLikes.Add(likes);
            }
        }
        #endregion
    }
}
